package com.washmadam.service.controller.cms.customer.communicate;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.washmadam.service.common.base.BaseController;
import com.washmadam.service.common.base.RequestDTO;
import com.washmadam.service.common.base.ResponseDTO;
import com.washmadam.service.common.constants.Constant;
import com.washmadam.service.common.enums.StatusEnum;
import com.washmadam.service.db.dto.CustomerOrderCommunicate;
import com.washmadam.service.domain.communicate.CustomerOrderCommunicateDomain;

import common.service.base.annotation.NoCheckSession;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(Constant.URL_PREFIX + "/cms/customer/communicate")
@Slf4j
public class CustomerOrderCommunicateCmsController extends BaseController {

	@Autowired
	CustomerOrderCommunicateDomain customerOrderCommunicateDomain;
	/**
	 * 
	 * @param 添加服务沟通
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/addServiceCommunicate")
	public String addServiceCommunicate(@RequestBody RequestDTO req, HttpServletRequest request) {
		try {
			log.info("【添加服务沟通】请求参数 data:{}", req.getData());
			if (req.getData() == null) {
				return ResponseDTO.fail("参数缺失", null);
			}
			CustomerOrderCommunicate requestParam = JSONObject.parseObject(JSON.toJSONString(req.getData()),
					CustomerOrderCommunicate.class);
			buildCreateAndUpdateInfo(requestParam);
			requestParam.setStatus(StatusEnum.ENABLE.getCode());
			requestParam.setHandlePerson(super.getSessionUser().getName());
			customerOrderCommunicateDomain.addServiceCommunicate(requestParam);
			//log.info("【新增订单】调用成功:result;{}", result);
			return ResponseDTO.success();
		} catch (Exception e) {
			log.error("【添加服务沟通】异常，{}", e);
			return ResponseDTO.fail("请求异常:" + e.getMessage(), null);
		}
	}
	/**
	 * 
	 * @param 添加订单沟通
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/addOrderCommunicate")
	@NoCheckSession
	public String addOrderCommunicate(@RequestBody RequestDTO req, HttpServletRequest request) {
		try {
			log.info("【添加订单沟通】请求参数 data:{}", req.getData());
			if (req.getData() == null) {
				return ResponseDTO.fail("参数缺失", null);
			}
			CustomerOrderCommunicate requestParam = JSONObject.parseObject(JSON.toJSONString(req.getData()),
					CustomerOrderCommunicate.class);
			buildCreateAndUpdateInfo(requestParam);
			requestParam.setStatus(StatusEnum.ENABLE.getCode());
			requestParam.setHandlePerson(super.getSessionUser().getName());
			customerOrderCommunicateDomain.addOrderCommunicate(requestParam);
			//log.info("【新增订单】调用成功:result;{}", result);
			return ResponseDTO.success();
		} catch (Exception e) {
			log.error("【添加订单沟通】异常，{}", e);
			return ResponseDTO.fail("请求异常:" + e.getMessage(), null);
		}
	}
}
